package com.yxq.mdt.app.modules.auction.model;

import com.yxq.mdt.app.base.RespBase;
import com.yxq.mdt.app.base.ibase.IBaseModel;
import com.yxq.mdt.app.modules.auction.bean.AuctionList;
import com.yxq.mdt.app.modules.auction.bean.AuctionProfitBean;
import com.yxq.mdt.app.modules.auction.bean.AuctionTxBean;
import com.yxq.mdt.app.modules.auction.bean.HonorValueBean;
import com.yxq.mdt.app.modules.auction.bean.MyTeamFansBean;
import com.yxq.mdt.app.modules.socialcontact.bean.MainSocialContactRecommendBean;
import com.yxq.mdt.app.modules.socialcontact.model.MainSocialContactApi;
import com.yxq.mdt.app.net.ApiModel;
import com.yxq.mdt.app.net.BaseObserver;
import com.yxq.mdt.app.net.RetrofitFactory;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import retrofit2.http.Field;
import retrofit2.http.Query;

/**
 * Created by L on 2019-10-18.
 */
public class AuctionModel implements IBaseModel {

    //查询自己的粉丝
    public void getAuctionFansList(int pageNum, int pageSize, ApiModel.CommonCallback<MyTeamFansBean> callback) {
        RetrofitFactory.getPMRetrofit().create(AuctionApi.class)
                .getPmUserFansByUserId(pageNum, pageSize)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<MyTeamFansBean>>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(RespBase<MyTeamFansBean> baseEntity) throws Exception {
                        if (baseEntity.getCode() == 200) {
                            callback.onSuccess(baseEntity.getData());
                        } else {
                            callback.onError(baseEntity.getMsg());
                        }
                    }
                });
    }

    //获取用户等级,荣誉值
    public static void getHonorValue(ApiModel.CommonCallback<HonorValueBean> callback) {
        RetrofitFactory.getPMRetrofit().create(AuctionApi.class)
                .getHonorValue()
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<HonorValueBean>>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(RespBase<HonorValueBean> baseEntity) throws Exception {
                        if (baseEntity.getCode() == 200) {
                            callback.onSuccess(baseEntity.getData());
                        } else {
                            callback.onError(baseEntity.getMsg());
                        }
                    }
                });
    }

    //分页查询拍卖列表,荣誉值
    public void getAuctionListByType(int type, int pageNum, int pageSize, ApiModel.CommonCallback<AuctionList> callback) {
        RetrofitFactory.getPMRetrofit().create(AuctionApi.class)
                .getAuctionListByType(type, pageNum, pageSize)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<AuctionList>>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(RespBase<AuctionList> baseEntity) throws Exception {
                        if (baseEntity.getCode() == 200) {
                            callback.onSuccess(baseEntity.getData());
                        } else {
                            callback.onError(baseEntity.getMsg());
                        }
                    }
                });
    }

    //获取提现记录以及提现总金额
    public void getUserCashList(String pageNum, String pageSize, ApiModel.CommonCallback<AuctionProfitBean> callback) {
        RetrofitFactory.getPMRetrofit().create(AuctionApi.class)
                .getUserCashList(pageNum, pageSize)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<AuctionProfitBean>>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(RespBase<AuctionProfitBean> baseEntity) throws Exception {
                        if (baseEntity.getCode() == 200) {
                            callback.onSuccess(baseEntity.getData());
                        } else {
                            callback.onError(baseEntity.getMsg());
                        }
                    }
                });
    }

    //团长申请接口
    public static void addPmUserGrade(String oldLevelId, String newLevelId, ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getPMRetrofit().create(AuctionApi.class)
                .addPmUserGrade(oldLevelId, newLevelId)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<String>>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(RespBase<String> baseEntity) throws Exception {
                        if (baseEntity.getCode() == 200) {
                            callback.onSuccess(baseEntity.getData());
                        } else {
                            callback.onError(baseEntity.getMsg());
                        }
                    }
                });
    }

    //获取收益记录以及提现金额
    public static void getUserIncomeList(int pageSize, int pageNum, String isEntry, ApiModel.CommonCallback<AuctionTxBean> callback) {
        RetrofitFactory.getPMRetrofit().create(AuctionApi.class)
                .getUserIncomeList(pageSize, pageNum, isEntry)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<AuctionTxBean>>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(RespBase<AuctionTxBean> baseEntity) throws Exception {
                        if (baseEntity.getCode() == 200) {
                            callback.onSuccess(baseEntity.getData());
                        } else {
                            callback.onError(baseEntity.getMsg());
                        }
                    }
                });
    }

    //提现申请接口
    public void addUserCash(String drillNo, String userName, String drillAmount, String userPhone, ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getPMRetrofit().create(AuctionApi.class)
                .addUserCash(drillNo, userName, drillAmount, userPhone)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<String>>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(RespBase<String> baseEntity) throws Exception {
                        if (baseEntity.getCode() == 200) {
                            callback.onSuccess(baseEntity.getData());
                        } else {
                            callback.onError(baseEntity.getMsg());
                        }
                    }
                });
    }

    public static void ifBecomeArea(ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getPMRetrofit().create(AuctionApi.class)
                .ifBecomeArea()
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<String>>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(RespBase<String> baseEntity) throws Exception {
                        if (baseEntity.getCode() == 200) {
                            callback.onSuccess(baseEntity.getData());
                        } else {
                            callback.onError(baseEntity.getMsg());
                        }
                    }
                });

    }

    public static void becomeArea(String userRealname, String userIdcard, String districtId, String userTel, ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getPMRetrofit().create(AuctionApi.class)
                .becomeArea(userRealname, userIdcard, districtId, userTel)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<String>>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(RespBase<String> baseEntity) throws Exception {
                        if (baseEntity.getCode() == 200) {
                            callback.onSuccess(baseEntity.getData());
                        } else {
                            callback.onError(baseEntity.getMsg());
                        }
                    }
                });

    }

    public static void getPmUserFansByUserId(int pageNum, int pageSize, ApiModel.CommonCallback<MyTeamFansBean> callback) {
        RetrofitFactory.getPMRetrofit().create(AuctionApi.class)
                .getPmUserFansByUserId(pageNum, pageSize)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<MyTeamFansBean>>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(RespBase<MyTeamFansBean> baseEntity) throws Exception {
                        if (baseEntity.getCode() == 200) {
                            callback.onSuccess(baseEntity.getData());
                        } else {
                            callback.onError(baseEntity.getMsg());
                        }
                    }
                });

    }

    public static void getPmUserFansWithLeveltwo(int pageNum, int pageSize, ApiModel.CommonCallback<MyTeamFansBean> callback) {
        RetrofitFactory.getPMRetrofit().create(AuctionApi.class)
                .getPmUserFansWithLeveltwo(pageNum, pageSize)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<MyTeamFansBean>>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(RespBase<MyTeamFansBean> baseEntity) throws Exception {
                        if (baseEntity.getCode() == 200) {
                            callback.onSuccess(baseEntity.getData());
                        } else {
                            callback.onError(baseEntity.getMsg());
                        }
                    }
                });

    }

    public static void hasArea(String districtId, ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getPMRetrofit().create(AuctionApi.class)
                .hasArea(districtId)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<String>>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(RespBase<String> baseEntity) throws Exception {
                        if (baseEntity.getCode() == 200) {
                            callback.onSuccess(baseEntity.getData());
                        } else {
                            callback.onError(baseEntity.getMsg());
                        }
                    }
                });
    }

    public static void getPrepared(ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getPMRetrofit().create(AuctionApi.class)
                .getPrepared()
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<String>>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(RespBase<String> baseEntity) throws Exception {
                        if (baseEntity.getCode() == 200) {
                            callback.onSuccess(baseEntity.getData());
                        } else {
                            callback.onError(baseEntity.getMsg());
                        }
                    }
                });
    }

    public static void applyPrepared(String userRealname, String userIdcard, String occupation, String userTel, ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getPMRetrofit().create(AuctionApi.class)
                .applyPrepared(userRealname, userIdcard, occupation, userTel)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<String>>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(RespBase<String> baseEntity) throws Exception {
                        if (baseEntity.getCode() == 200) {
                            callback.onSuccess(baseEntity.getData());
                        } else {
                            callback.onError(baseEntity.getMsg());
                        }
                    }
                });

    }

    public static void getGiftNumber(ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getPMRetrofit().create(AuctionApi.class)
                .getGiftNumber()
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<String>>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(RespBase<String> baseEntity) throws Exception {
                        if (baseEntity.getCode() == 200) {
                            callback.onSuccess(baseEntity.getData());
                        } else {
                            callback.onError(baseEntity.getMsg());
                        }
                    }
                });
    }

    public static void getCountWithLevelone(ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getPMRetrofit().create(AuctionApi.class)
                .getCountWithLevelone()
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<String>>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(RespBase<String> baseEntity) throws Exception {
                        if (baseEntity.getCode() == 200) {
                            callback.onSuccess(baseEntity.getData());
                        } else {
                            callback.onError(baseEntity.getMsg());
                        }
                    }
                });
    }

    @Override
    public void onDestroy() {

    }
}
